<?php
/**@var \Weline\Framework\View\Template $this */
/**@var \Weline\Backend\Block\ThemeConfig $themeConfig */
$themeConfig = \Weline\Framework\Manager\ObjectManager::getInstance(\Weline\Backend\Block\ThemeConfig::class);
?>
<!DOCTYPE html>
<!--
 *@Author       秋枫雁飞
 *@Email        aiweline@qq.com
 *@Forum        https://bbs.aiweline.com
 *@DESC         后台共用头部
-->
<html lang="en" <?= ('rtl' === $themeConfig->getThemeModel()) ? " dir=\"rtl\"" : '' ?>>
<head>
    <title><lang>Weline Admin 管理面板</lang></title>
    <!--模板Weline_Admin::common/head.phtml-->
    <w:template>Weline_Admin::common/head.phtml</w:template>
    <!-- jvectormap -->
    <w:css>Weline_Admin::assets/libs/jqvmap/jqvmap.min.css</w:css>
    <!-- Responsive Table css -->
    <link href='@static(Weline_Admin::assets/libs/admin-resources/rwd-table/rwd-table.min.css)' rel='stylesheet'
          type='text/css'/>
    <!-- Sweet Alert-->
    <link href='@static(Weline_Admin::assets/libs/sweetalert2/sweetalert2.min.css)' rel='stylesheet' type='text/css'/>
</head>

<!--<body data-sidebar="dark" data-topbar='colored' data-layout='horizontal'>-->
<body <?= $themeConfig->getLayouts() ?? ''; ?>>
<!--加载中组件 开始-->
@template(Weline_Admin::common/page/loading.phtml)
<!-- 开始 页面 -->
<div id="layout-wrapper">

    <!--页头工具条 开始-->
    <w:block class="Weline\Admin\Block\Backend\Page\Topbar"/>
    <!--页头工具条 结束-->
    <!-- ========== Topnav Start ========== -->
    <!--页头菜单栏 开始-->
    <w:block class='Weline\Admin\Block\Backend\Page\Topnav' />
    <!--页头菜单栏 结束-->

    <!-- ========== Left Sidebar Start ========== -->
    <!--左侧菜单栏 开始-->
    @template(Weline_Admin::common/left-sidebar.phtml)
    <!--左侧菜单栏 结束-->


    <!-- ============================================================== -->
    <!-- Start right Content here -->
    <!-- ============================================================== -->
    <div class="main-content">

        <div class="page-content" style="min-height: 800px">
            <div class="container-fluid">
                <div class='row'>
                    <!--消息-->
                    <template>Weline_Component::message.phtml</template>
                    <div class='col-12'>
                        <div class='card'>
                            <div class='card-body'>
                                <h4 class='card-title'>
                                    <lang>开发文档</lang>
                                </h4>
                                <p class='card-title-desc'>
                                    <lang>编写开发文档</lang>
                                </p>
                                <div class="panel card">
                                    <div class="panel-body">
                                        <div class="row">
                                            <div class='col-6 pull-left'>
                                            </div>
                                            <div class='col-6 button-items'>
                                                <a href="@admin-url('dev/tool/admin/document/add')">
                                                    <button type='button'
                                                            class='btn btn-success waves-effect waves-light pull-right'>
                                                        <lang>新增文章</lang>
                                                    </button>
                                                </a>
                                                <a href="@admin-url('dev/tool/admin/document/catalog')">
                                                    <button type='button'
                                                            class='btn btn-info waves-effect waves-light pull-right'>
                                                        <lang>目录管理</lang>
                                                    </button>
                                                </a>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class='table-rep-plugin'>
                                    <div class='table-responsive mb-0' data-pattern='priority-columns'>
                                        <table id='tech-companies-1' class='table table-hover table-bordered'>
                                            <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>分类</th>
                                                <th>标题</th>
                                                <th>简介</th>
                                                <th>作者ID</th>
                                                <th>创建时间</th>
                                                <th>更新时间</th>
                                                <th>
                                                    <lang>操作</lang>
                                                </th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <empty name="documents">
                                                <tr>
                                                    <th colspan="8" class="text-center">
                                                        <lang>暂无文章</lang>
                                                    </th>
                                                </tr>
                                            </empty>
                                            <foreach name="documents" item="vo">
                                                <tr>
                                                    <th>
                                                        <var>vo.doc_id</var>
                                                    </th>
                                                    <th>
                                                        <a target="_blank"
                                                           href="@url('/dev/tool/catalog',['id'=>$vo['c_id']])"><var>vo.c_name</var></a>
                                                    </th>
                                                    <th>
                                                        <var>vo.title</var>
                                                    </th>
                                                    <th>
                                                        <var>vo.summary</var>
                                                    </th>
                                                    <th>
                                                        <var>vo.author_id</var>
                                                    </th>

                                                    <th>
                                                        <var>vo.create_time</var>
                                                    </th>

                                                    <th>
                                                        <var>vo.update_time</var>
                                                    </th>

                                                    <th>
                                                        <button data-url="@admin-url{'dev/tool/admin/document/delete',['id'=>$vo->getData('doc_id')]}"
                                                                class='btn btn-danger btn waves-effect waves-light document-delete-btn'>
                                                            删除
                                                        </button>
                                                        <a href="@admin-url{'dev/tool/admin/document/edit',['id'=>$vo->getData('doc_id')]}">
                                                            <button class="btn btn-primary">编辑</button>
                                                        </a>
                                                    </th>
                                                </tr>
                                            </foreach>
                                            </tbody>
                                        </table>
                                        <?php
                                        $pagination = $this->getData('pagination');
                                        echo $pagination['html'] ?? '';
                                        ?>
                                    </div>

                                </div>

                            </div>
                        </div>
                    </div> <!-- end col -->
                </div> <!-- end row -->
            </div>
            <!-- container-fluid -->
        </div>
        <!-- End Page-content -->

        <footer class="footer">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-6">
                        <script>document.write(new Date().getFullYear())</script>
                        © Weline.
                    </div>
                    <div class="col-sm-6">
                        <div class="text-sm-end d-none d-sm-block">
                            Crafted with <i class="mdi mdi-heart text-danger"></i> By <a
                                    href="https://www.aiweline.com/">秋枫雁飞(aiweline)</a>
                        </div>
                    </div>
                </div>
            </div>
        </footer>

    </div>
    <!-- end main content-->

</div>
<!-- END layout-wrapper -->

<!--右边栏-->
@template(Weline_Admin::common/right-sidebar.phtml)
<!--tinymce js-->
<script src='@static(Weline_Admin::assets/libs/tinymce/tinymce.min.js)'></script>

<!-- init js -->
<script src='@static(Weline_Admin::assets/js/pages/form-editor.init.js)'></script>

<!-- Responsive Table js -->
<script src='@static(Weline_Admin::assets/libs/admin-resources/rwd-table/rwd-table.min.js)'></script>

<!-- Init js -->
<script src='@static(Weline_Admin::assets/js/pages/table-responsive.init.js)'></script>
<!-- Sweet Alerts js -->
<script src='@static(Weline_Admin::assets/libs/sweetalert2/sweetalert2.min.js)'></script>

<!--页脚-->
@template(Weline_Admin::common/footer.phtml)

<!-- jquery.vectormap map -->
<script src="@static(Weline_Admin::assets/libs/jqvmap/jquery.vmap.min.js)"></script>
<script src="@static(Weline_Admin::assets/libs/jqvmap/maps/jquery.vmap.usa.js)"></script>
<!--按钮-->
<script>
    $('.document-delete-btn').click(function (e) {
        let target = $(e.target)
        Swal.fire({
            title: '@lang("你确定要操作么？")',
            text: '@lang("操作后你将无法恢复！")',
            icon: 'warning',
            showCancelButton: true,
            confirmButtonText: '@lang("是的，我确定要删除！")',
            cancelButtonText: '@lang(不要，取消吧！)',
            confirmButtonClass: 'btn btn-success mt-2',
            cancelButtonClass: 'btn btn-danger ms-2 mt-2',
            buttonsStyling: false
        }).then(function (result) {
            if (result.value) {
                showLoading();
                $.post({
                    url: target.attr('data-url')
                }).done(res => {
                    hideLoading();
                    console.log(res)
                    if (200 === res.code) {
                        Swal.fire({
                            title: '@lang("已删除！")',
                            text: '@lang("文章已经被删除了！")',
                            confirmButtonText: '@lang(好的)',
                            icon: 'success'
                        }).then(res => {
                            if (res.value) window.location.reload()
                        })
                    } else {
                        Swal.fire({
                            title: '@lang(删除提示！)',
                            text: '@lang("文章删除失败，请重试！")',
                            confirmButtonText: '@lang(好的)',
                            icon: 'error'
                        })
                    }
                })
            } else if (
                // Read more about handling dismissals
                result.dismiss === Swal.DismissReason.cancel
            ) {
                Swal.fire({
                    title: '@lang("已取消删除！")',
                    text: '@lang("这篇文章安全的保留下来了！"):)',
                    confirmButtonText: '@lang(好的)',
                    icon: 'error'
                })
            }
        });
    });
</script>
</body>
</html>

